/**
 * 2017年5月1日
 */
package cn.edu.bjtu.entity.impl.api;

import java.io.InputStream;
import java.net.URI;
import java.util.Map;
import java.util.concurrent.locks.ReadWriteLock;

import org.apache.http.HttpEntity;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;

import cn.edu.bjtu.constant.Constant;
import pojo.dto.services.DocumentVectorMessage;


/**
 * @author Alex
 *
 */
public class Word2VecDocTransContext extends Word2VecBaseContext<DocumentVectorMessage>{
	String uri =  "/post/trans";
	String text = null;
	
	
	public Word2VecDocTransContext(ReadWriteLock lock) {
		super(lock);
	}
	
	public void setText(String s){
		text = s;
	}
	
	public String getMethod() {
		return METHOD_POST;
	};
	@Override
	public HttpEntity getPostEntity() {
		HttpEntity he = new StringEntity("text="+this.text+"\n", ContentType.APPLICATION_FORM_URLENCODED);
		return he;
	}
	@Override
	public Map<String, Object> getResultMapForRender() {
		return this.resultMap;
	}

	@Override
	public URI getURI() {
		return URI.create(uri);
	}
	private DocumentVectorMessage dvm;
	@Override
	protected void handleResponseInputStream(InputStream in, HttpEntity entity) throws Exception  {
			dvm  = om.readValue(in, DocumentVectorMessage.class);
			this.msg = dvm.getMsg();
			resultMap.put(Constant.COMMAND_RESULT, dvm);
			this.msg = "转的成功";
	}

	@Override
	public DocumentVectorMessage javaClassResult() {
		return dvm;
	}


}
